<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI 端模型- 前端开发的时代</title>
</head>

<body>
    <script src="./brain.js"></script>
    <script>
        // 训练数据: 给模型训练数据,让模型去学习, 

        const data1 = [

            {
                "input": "implementing a caching mechanism improves performance",
                "output": "backend"
            },
            {
                "input": "hover effects on buttons",
                "output": "frontend"
            },
            {
                "input": "optimizing SQL queries",
                "output": "backend"
            },
            {
                "input": "using flexbox for layout",
                "output": "frontend"
            },
            {
                "input": "setting up a CI/CD pipeline",
                "output": "backend"
            },
            {
                "input": "SVG animations for interactive graphics",
                "output": "frontend"
            },
            {
                "input": "authentication using OAuth",
                "output": "backend"
            },
            {
                "input": "responsive images for different screen sizes",
                "output": "frontend"
            },
            {
                "input": "creating REST API endpoints",
                "output": "backend"
            },
            {
                "input": "CSS grid for complex layouts",
                "output": "frontend"
            },
            {
                "input": "database normalization for efficiency",
                "output": "backend"
            },
            {
                "input": "custom form validation",
                "output": "frontend"
            },
            {
                "input": "implementing web sockets for real-time communication",
                "output": "backend"
            },
            {
                "input": "parallax scrolling effect",
                "output": "frontend"
            },
            {
                "input": "securely storing user passwords",
                "output": "backend"
            },
            {
                "input": "creating a theme switcher (dark/light mode)",
                "output": "frontend"
            },
            {
                "input": "load balancing for high traffic",
                "output": "backend"
            },
            {
                "input": "accessibility features for disabled users",
                "output": "frontend"
            },
            {
                "input": "scalable architecture for growing user base",
                "output": "backend"
            }
        ];

        //训练
        const data2=[
                {
                    input: [1, 1],
                    output: [1]
                },
                {
                    input: [0, 1],
                    output: [0]
                },
                {
                    input: [1, 0],
                    output: [0]
                },
            ];
        const data3=[
            'Hello there',
            'How are you?',
            'Hello world',
            'Good morning'
        ];       
        const data4=[
            {
                "input": "This is a great movie with amazing acting.",
                "output": "positive"
            },
            {
                "input": "I love this book. It's a great amazing.",
                "output": "positive"
            },
            {
                "input": "The service at this restaurant was really bad.",
                "output": "negative"
            },
        ]
   
        
        
        
        // 初始化一个神经网络
        const network = new brain.Recurrent();

        //训练神经网络 ,花的时间很长
        // network.train(data1,{
        //   iterations: 2000,
        //   log : true,
        //   logPeriod: 100,
        // });

        network.train(data4);

        // 执行训练好的模型进行预测!
        const output = network.run('The service at this restaurant was really bad');

        //console.log('输出的结果是 : '+output);

        alert(`预测的output是: ${output}`)
    </script>
</body>

</html>